import 'package:flutter/material.dart';
import 'package:matrix_gesture_detector_pro/matrix_gesture_detector_pro.dart';

void main() => runApp(
    MaterialApp(debugShowCheckedModeBanner: false, home: DragImgDemoPage()));

class DragImgDemoPage extends StatefulWidget {
  const DragImgDemoPage({super.key});

  @override
  _DragImgDemoPageState createState() => _DragImgDemoPageState();
}

class _DragImgDemoPageState extends State<DragImgDemoPage> {


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("DragImgDemoPage"),
      ),
      body: GestureDetector(
        onDoubleTap: () {
          transform = Matrix4.diagonal3Values(1, 1, 1.0);
          setState(() {});
        },
        child: buildMatrixGestureDetector(context),
      ),
    );
  }
  //定义变换的矩阵
  Matrix4 transform = Matrix4.diagonal3Values(1, 1, 1.0);
  //实现旋转、平移、缩放
  MatrixGestureDetector buildMatrixGestureDetector(BuildContext context) {
    return MatrixGestureDetector(
      onMatrixUpdate: (
        Matrix4 matrix,
        Matrix4 translationDeltaMatrix,
        Matrix4 scaleDeltaMatrix,
        Matrix4 rotationDeltaMatrix,
      ) {
        setState(() {
          transform = matrix;
        });
      },
      child: Transform(
        transform: transform,
        child: Image.asset(
          "assets/images/banner3.png",
          fit: BoxFit.fitWidth,
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
        ),
      ),
    );
  }
}
